package leetcode_300;
/**
 *@author 周杨
 *HIndexII_275 给有序数组求H指数
 *describe:用二叉搜索 AC 83%
 *2018年6月26日 下午4:51:42
 */
public class HIndexII_275 {
	public static void main(String[] args) {
		HIndexII_275 test=new HIndexII_275();
		System.out.println(test.hIndex(new int[]{0,1,3,5,6}));
	}
	public int hIndex(int[] citations) {
		if (citations == null || citations.length < 1) {
            return 0;
        }
		int r=citations.length-1,l=0;
		while(l<=r) {
			int mid=(r+l)>>1;
			if(citations[mid]==citations.length-mid)
				return citations[mid];
			else if(citations[mid]<citations.length-mid)
				l=mid+1;
			else
				r=mid-1;
		}
        return citations.length-l;
    }
}
